#!/bin/bash

# Props Management Starter Builder
# Multi-module version

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo -e "${BLUE}🔧 Building Props Management Starter...${NC}"
echo "==========================================="

# Check Java version
echo -e "${GREEN}✅ Java version:${NC} $(java -version 2>&1 | head -n 1)"

# Check Maven version
echo -e "${GREEN}✅ Maven version:${NC} $(mvn -version 2>&1 | head -n 1)"

# Clean and compile parent project
echo -e "${BLUE}📦 Cleaning and compiling parent project...${NC}"
mvn clean compile -q
if [ $? -eq 0 ]; then
    echo -e "${GREEN}✅ Parent project compiled successfully!${NC}"
else
    echo -e "${RED}❌ Parent project compilation failed!${NC}"
    exit 1
fi

# Package starter module
echo -e "${BLUE}📦 Packaging starter module...${NC}"
mvn package -pl props-starter -q
if [ $? -eq 0 ]; then
    echo -e "${GREEN}✅ Starter module packaged successfully!${NC}"
else
    echo -e "${RED}❌ Starter module packaging failed!${NC}"
    exit 1
fi

# Install starter module to local repository
echo -e "${BLUE}📦 Installing starter module to local repository...${NC}"
mvn install -pl props-starter -q
if [ $? -eq 0 ]; then
    echo -e "${GREEN}✅ Starter module installed to local repository!${NC}"
else
    echo -e "${RED}❌ Starter module installation failed!${NC}"
    exit 1
fi

echo -e "${GREEN}🎉 Props Management Starter build completed successfully!${NC}"
echo "========================================================="
echo -e "${YELLOW}📄 Artifact Information:${NC}"
echo -e "   Group ID: com.props"
echo -e "   Artifact ID: props-management-spring-boot-starter"
echo -e "   Version: 1.0.0"
echo -e "   Location: ~/.m2/repository/com/props/props-management-spring-boot-starter/1.0.0/"
echo ""
echo -e "${YELLOW}🚀 Usage in other projects:${NC}"
echo -e "   Add the following dependency to your pom.xml:"
echo -e "   <dependency>"
echo -e "       <groupId>com.props</groupId>"
echo -e "       <artifactId>props-management-spring-boot-starter</artifactId>"
echo -e "       <version>1.0.0</version>"
echo -e "   </dependency>" 